//
//  loginTextField.m
//  FashionShow
//
//  Created by 张龙 on 2017/2/27.
//
//

#import "loginTextField.h"

@interface loginTextField()<UITextFieldDelegate>
@end

@implementation loginTextField


- (id)initWithFrame:(CGRect)frame placeholder:(NSString *)placeholderstr imageStr:(NSString *)imageStr {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.autocorrectionType = UITextAutocorrectionTypeNo;//禁用自动纠正
        self.clearButtonMode = UITextFieldViewModeWhileEditing;//编辑时清除
        self.autocapitalizationType = UITextAutocapitalizationTypeNone;//消除自动大小写
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;//UITextField 的字的摆设方式
        self.keyboardType = UIKeyboardTypeDefault;
        self.borderStyle = UITextBorderStyleNone;
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 2;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.layer.borderWidth = 1;
//        self.adjustsFontSizeToFitWidth = YES;
//        NSMutableAttributedString *resultString=[[NSMutableAttributedString alloc]initWithString:placeholderstr];
//        [resultString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:8] range:NSMakeRange(0, resultString.length)];
//        self.attributedPlaceholder = [[NSAttributedString alloc]initWithAttributedString:resultString];
        
        [self setPlaceholder: [NSString stringWithFormat:@"%@",placeholderstr]];
    }
    self.returnKeyType = UIReturnKeyDefault;
    
    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 20)];
    self.leftView = leftView;
    self.leftViewMode = UITextFieldViewModeAlways;
    if (!strIsEmpty(imageStr)) {
        leftView.frame = CGRectMake(0, 0, 25, 20);
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageStr]];
        imageView.frame = CGRectMake(5, 0, 15, 20);
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        [leftView addSubview:imageView];
    }
    [self setFont:[UIFont systemFontOfSize:16]];
    self.textColor = KTEXTMAINCOLOR;

    self.delegate = self;
    return self;
}
@end
